<html>
<head><meta charset="utf-8"><title>emacs / lsp compatibility · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/emacs.20.2F.20lsp.20compatibility.html">emacs / lsp compatibility</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="158658946"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/emacs%20/%20lsp%20compatibility/near/158658946" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Andreas Fuchs <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/emacs.20.2F.20lsp.20compatibility.html#158658946">(Feb 15 2019 at 23:24)</a>:</h4>
<p>I just tried connecting the current HEAD of rust-analyzer to emacs's lsp-mode and it kinda works! All that's required is to put in this definition:</p>
<div class="codehilite"><pre><span></span><span class="p">(</span><span class="nv">lsp-register-client</span>
 <span class="p">(</span><span class="nv">make-lsp-client</span> <span class="nb">:new-connection</span> <span class="p">(</span><span class="nv">lsp-stdio-connection</span> <span class="o">&#39;</span><span class="p">(</span><span class="s">&quot;ra_lsp_server&quot;</span><span class="p">))</span>
                  <span class="nb">:major-modes</span> <span class="o">&#39;</span><span class="p">(</span><span class="nv">rust-mode</span> <span class="nv">rustic-mode</span><span class="p">)</span>
                  <span class="nb">:priority</span> <span class="mi">99</span>
                  <span class="nb">:server-id</span> <span class="ss">&#39;ra_lsp_server</span>
                  <span class="nb">:notification-handlers</span> <span class="p">(</span><span class="nv">lsp-ht</span> <span class="p">(</span><span class="s">&quot;window/progress&quot;</span> <span class="ss">&#39;lsp-clients--rust-window-progress</span><span class="p">))))</span>
</pre></div>


<p>and you get just about all the features that rust-analyzer's LSP server can deliver. Unfortunately, lsp-ui mode doesn't look pretty with it, mostly because symbol resolution isn't working well yet (most symbols/types/traits from other packages get a "not implemented" message). However, some code completion via company-mode, the documentation popup and go-to-definition do work!</p>



<a name="158658969"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/emacs%20/%20lsp%20compatibility/near/158658969" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Andreas Fuchs <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/emacs.20.2F.20lsp.20compatibility.html#158658969">(Feb 15 2019 at 23:25)</a>:</h4>
<p>Note the <code>:priority 99</code> there - that instructs LSP to prefer ra_lsp_server to the built-in <code>rls</code> definition.</p>



<a name="158661675"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/emacs%20/%20lsp%20compatibility/near/158661675" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/emacs.20.2F.20lsp.20compatibility.html#158661675">(Feb 16 2019 at 00:07)</a>:</h4>
<p>I've been using RA with emacs the whole time, actually :) I've got some code to handle <code>rust-analyzer.applySourceChange</code> as well, so code actions etc. work, but there's a lot missing still...</p>



<a name="158663987"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/emacs%20/%20lsp%20compatibility/near/158663987" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Andreas Fuchs <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/emacs.20.2F.20lsp.20compatibility.html#158663987">(Feb 16 2019 at 00:49)</a>:</h4>
<p>Whoa, I'd love to see that code action change - I'd been trying them and only getting errors about unsupported commands (:</p>



<a name="158682267"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/emacs%20/%20lsp%20compatibility/near/158682267" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/emacs.20.2F.20lsp.20compatibility.html#158682267">(Feb 16 2019 at 07:13)</a>:</h4>
<p>Speaking of LSP clients, I've found one that didn't send the <code>initialized</code> notification, making <code>rust-analyzer</code> panic. I wouldn't be surprised if other clients did the same. Maybe we should have a debugging option to trace the client-server communication?</p>



<a name="158687200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/emacs%20/%20lsp%20compatibility/near/158687200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/emacs.20.2F.20lsp.20compatibility.html#158687200">(Feb 16 2019 at 09:48)</a>:</h4>
<blockquote>
<p>I just tried connecting the current HEAD of rust-analyzer to emacs's lsp-mode and it kinda works! All that's required is to put in this definition:</p>
<p>I've got some code to handle rust-analyzer.applySourceChange as well, so code actions etc. </p>
</blockquote>
<p>There's editors/emacs folder in the repo ;) Would be cool to have these things there.</p>



<a name="158687219"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/emacs%20/%20lsp%20compatibility/near/158687219" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/emacs.20.2F.20lsp.20compatibility.html#158687219">(Feb 16 2019 at 09:49)</a>:</h4>
<blockquote>
<p>I've found one that didn't send the initialized notification, making rust-analyzer panic.</p>
</blockquote>
<p>Yeah, that's a common violation of the speck in the clients. I've personally fixed eglot and kak-lsp =)</p>
<blockquote>
<p>Maybe we should have a debugging option to trace the client-server communication?</p>
</blockquote>
<p>export RUST_LOG=gen_lsp_server=debug</p>



<a name="158687831"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/emacs%20/%20lsp%20compatibility/near/158687831" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/emacs.20.2F.20lsp.20compatibility.html#158687831">(Feb 16 2019 at 10:06)</a>:</h4>
<p>oh, right (:</p>



<a name="158690689"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/emacs%20/%20lsp%20compatibility/near/158690689" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/emacs.20.2F.20lsp.20compatibility.html#158690689">(Feb 16 2019 at 11:28)</a>:</h4>
<blockquote>
<p>Whoa, I'd love to see that code action change - I'd been trying them and only getting errors about unsupported commands (:</p>
</blockquote>
<p><a href="https://github.com/flodiebold/lsp-rust/blob/ra/lsp-rust.el#L169-L193" target="_blank" title="https://github.com/flodiebold/lsp-rust/blob/ra/lsp-rust.el#L169-L193">https://github.com/flodiebold/lsp-rust/blob/ra/lsp-rust.el#L169-L193</a></p>



<a name="158697588"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/emacs%20/%20lsp%20compatibility/near/158697588" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/emacs.20.2F.20lsp.20compatibility.html#158697588">(Feb 16 2019 at 14:28)</a>:</h4>
<p><span class="user-mention" data-user-id="204153">@Andreas Fuchs</span> I've cleaned up and extended my code a bit: <a href="https://github.com/rust-analyzer/rust-analyzer/pull/841" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/pull/841">https://github.com/rust-analyzer/rust-analyzer/pull/841</a></p>



<a name="158753583"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/emacs%20/%20lsp%20compatibility/near/158753583" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Andreas Fuchs <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/emacs.20.2F.20lsp.20compatibility.html#158753583">(Feb 17 2019 at 18:16)</a>:</h4>
<p>this is wonderful! Thanks for PR'ing it!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>